home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Graphics / Gnuplot / Source / AxesPane.m < prev    next >
Encoding:
Text File  |  1993-03-18  |  8.7 KB  |  400 lines

  1.  
  2. static char RCSId[]="$Id: AxesPane.m,v 1.1.1.1 1993/03/18 03:31:11 davis Exp $";
  3.  
  4.  
  5. #import <appkit/Application.h>
  6. #import <appkit/Button.h>
  7. #import <appkit/Form.h>
  8. #import <appkit/Matrix.h>
  9. #import <appkit/Panel.h>        /* NXRunAlertPanel()        */
  10. #import <appkit/PopUpList.h>
  11. #import <appkit/Text.h>            /* This Pane is a text delegate    */
  12. #import <appkit/TextFieldCell.h>
  13. #import <appkit/View.h>
  14.  
  15. #import <objc/NXStringTable.h>
  16.  
  17. #import "AxesPane.h"
  18. #import "GnuplotPlot.h"
  19. #import "Status.h"
  20. #import "StatusTics.h"
  21. #import "TicCell.h"
  22. #import "TicObject.h"
  23. #import "TicOptionsPanel.h"
  24.  
  25.  
  26. @interface AxesPane (Private)
  27.  
  28. - _updateLabelIsThreeD:(BOOL)isThreeD;
  29. - _updateTicsIsThreeD:(BOOL)isThreeD;
  30. - _updateRangeIsThreeD:(BOOL)isThreeD isPolar:(BOOL)isPolar;
  31.  
  32. @end
  33.  
  34.  
  35.  
  36. @implementation AxesPane
  37.  
  38.  
  39. - init
  40. {
  41.     [super init];
  42.  
  43.     [NXApp loadNibSection: "AxesPane.nib"
  44.             owner: self
  45.         withNames: NO
  46.          fromZone: [self zone]];
  47.  
  48.     view = [window setContentView:[[View alloc] init]];
  49.     icon = "InspectorAxes.tiff";
  50.     ticOptionsPanel = nil;
  51.  
  52.     return self;
  53. }
  54.  
  55.  
  56. /*  
  57.  *  Overridden from Pane.
  58.  */
  59. - selectControl:sender
  60. {
  61.     if ([[rangeAutoMatrix findCellWithTag:X_TAG] state] &&
  62.     [[rangeAutoMatrix findCellWithTag:Y_TAG] state] &&
  63.     [[rangeAutoMatrix findCellWithTag:Z_TAG] state])
  64.  
  65.     [labelMatrix selectText:self];
  66.  
  67.     else
  68.     [rangeMatrix selectText:self];
  69.  
  70.     return self;
  71. }
  72.  
  73.  
  74.  
  75. - updateStatus:aStatus doc:aDoc
  76. {
  77.     id oldStatus = status;
  78.  
  79.     /*  
  80.      *  We only bother updating if status has changed since we last 
  81.      *  updated, or if we just became the current pane (didSwap) -- 
  82.      *  assuming that status and aDoc are non-nil, of course.
  83.      */
  84.  
  85.     if ([super updateStatus:aStatus doc:aDoc]
  86.     && ((status != oldStatus) || didSwap)) {
  87.  
  88.     BOOL isThreeD, isPolar;
  89.     Window *viewWindow;
  90.     id cell;
  91.  
  92.     [(viewWindow = [view window]) disableDisplay];
  93.  
  94.     [axisXButton setState:[status axisX]];
  95.     [axisXButton setEnabled:!(isThreeD = [status isThreeD])];
  96.     [axisYButton setState:[status axisY]];
  97.     [axisYButton setEnabled:!isThreeD];
  98.     [axisTitleField setTextGray:isThreeD? NX_DKGRAY :NX_BLACK];
  99.     [gridButton setState:[status grid]];
  100.     [gridButton setEnabled:!(isPolar = [status isPolar])];
  101.  
  102.     [[logMatrix findCellWithTag:X_TAG] setState:[status isLogCoord:X_TAG]];
  103.     [[logMatrix findCellWithTag:Y_TAG] setState:[status isLogCoord:Y_TAG]];
  104.     [cell = [logMatrix findCellWithTag:Z_TAG] setState:
  105.                 [status isLogCoord:Z_TAG] && !isPolar];
  106.     [cell setEnabled:isThreeD];
  107.     [logMatrix display];
  108.     
  109.     [anglesButton setEnabled:isPolar];
  110.     [anglesButton setTitle:[status degrees]? "Degrees" :"Radians"];
  111.  
  112.     [self _updateLabelIsThreeD:isThreeD];
  113.     [self _updateTicsIsThreeD:isThreeD];
  114.     [self _updateRangeIsThreeD:isThreeD isPolar:isPolar];
  115.  
  116.     [viewWindow reenableDisplay];
  117.  
  118.     [self perform:@selector(selectControl:)
  119.          with:self
  120.        afterDelay:1
  121.        cancelPrevious:YES];
  122.  
  123.     didSwap = NO;
  124.     return self;
  125.  
  126.     }
  127.  
  128.     return nil;
  129. }
  130.  
  131.  
  132. - (BOOL)forceUpdateStatus:aStatus doc:aDoc
  133. {
  134.     if ([[ticOptionsPanel panel] isVisible])
  135.     [ticOptionsPanel forceUpdate];
  136.  
  137.     return [super forceUpdateStatus:aStatus doc:aDoc];
  138. }
  139.  
  140.  
  141. - didSwapIn:sender
  142. {
  143.     [super didSwapIn:self];
  144.     didSwap = YES;
  145.     return self;
  146. }
  147.  
  148.  
  149.  
  150. - doSetRange:sender
  151. {
  152.     int tag = [[sender selectedCell] tag];
  153.     BOOL isPolar = [status isPolar];
  154.  
  155.     double min = [[sender cellAt:tag :0] doubleValue];
  156.     double max = [[sender cellAt:tag :1] doubleValue];
  157.  
  158.     if (min == max)
  159.         NXRunAlertPanel ([stringSet valueForStringKey: "range"],
  160.                          [stringSet valueForStringKey: "zeroRange"],
  161.                          NULL, NULL, NULL);
  162.     else  {
  163.         if (isPolar && (tag == Z_TAG))  tag = R_TAG;
  164.  
  165.         if ([status isLogCoord:tag] && ((min <= 0) || (max <= 0)))
  166.             NXRunAlertPanel ([stringSet valueForStringKey: "log"],
  167.                              [stringSet valueForStringKey: "logRange"],
  168.                              NULL, NULL, NULL);
  169.         else
  170.             [status setRangeCoord:tag min:min max:max];
  171.     }
  172.  
  173.     [self _updateRangeIsThreeD:[status isThreeD] isPolar:isPolar];
  174.     return self;
  175. }
  176.  
  177.  
  178. - doSetRangeAuto:sender
  179. {
  180.     id cell = [sender selectedCell];
  181.     int tag = [cell tag];
  182.     BOOL isPolar = [status isPolar];
  183.  
  184.     [status setAutoscaleCoord:(tag == Z_TAG)? (isPolar? R_TAG :Z_TAG) :tag
  185.                          isOn: [cell state]];
  186.  
  187.     [self _updateRangeIsThreeD:[status isThreeD] isPolar:isPolar];
  188.     [rangeMatrix selectTextAt:tag :0];
  189.     return self;
  190. }
  191.  
  192.  
  193.  
  194. - doSetLog:sender
  195. {
  196.     id cell = [sender selectedCell];
  197.     int tag = [cell tag];
  198.     BOOL state = [cell state];
  199.     BOOL isPolar = [status isPolar];
  200.     double min = [[rangeMatrix cellAt:tag :0] doubleValue];
  201.     double max = [[rangeMatrix cellAt:tag :1] doubleValue];
  202.  
  203.     if ( state && ((min <= 0) || (max <= 0)) )  {
  204.         NXRunAlertPanel ([stringSet valueForStringKey: "log"],
  205.                          [stringSet valueForStringKey: "logRange"],
  206.                          NULL, NULL, NULL);
  207.         [cell setState:0];
  208.         return nil;
  209.     } else
  210.         return [status setIsLogCoord:(tag == Z_TAG)? (isPolar?R_TAG:Z_TAG) :tag
  211.                               isOn:state];
  212. }
  213.  
  214.  
  215.  
  216. - doSetAngles:sender
  217. {
  218.     int tag = [sender selectedTag];
  219.  
  220.     if (tag != oldAnglesTag) {
  221.         [status setDegrees:tag == ANGLES_DEGREES];
  222.         [self _updateRangeIsThreeD:[status isThreeD] isPolar:[status isPolar]];
  223.         oldAnglesTag = tag;
  224.     }
  225.  
  226.     return self;
  227. }
  228.  
  229.  
  230.  
  231. - doSetLabel:sender
  232. {
  233.     id cell = [sender selectedCell];
  234.  
  235.     [status setLabelCoord:[cell tag] to:[cell stringValue]];
  236.     return self;
  237. }
  238.  
  239.  
  240.  
  241. - doSetTics:sender
  242. {
  243.     TicCell *cell = [sender selectedCell];
  244.  
  245.     [status setTicsCoord:[cell tag] isOn:[cell state]];
  246.     [self _updateTicsIsThreeD:[status isThreeD]];
  247.  
  248.     return self;
  249. }
  250.  
  251.  
  252.  
  253. - doSetAxisX:sender
  254. {
  255.     return [status setAxisX:[sender state]];
  256. }
  257.  
  258.  
  259.  
  260. - doSetAxisY:sender
  261. {
  262.     return [status setAxisY:[sender state]];
  263. }
  264.  
  265.  
  266.  
  267. - doSetGrid:sender
  268. {
  269.     return [status setGrid:[sender state]];
  270. }
  271.  
  272.  
  273.  
  274. - doSetTicsIn:sender
  275. {
  276.     return [status setTicsIn:([ticsInMatrix selectedTag] == 0)];
  277. }
  278.  
  279.  
  280.  
  281. - showTicOptionsPanel:sender
  282. {
  283.     if (!ticOptionsPanel)
  284.     ticOptionsPanel = [[TicOptionsPanel allocFromZone:[self zone]] init];
  285.     [ticOptionsPanel showPanel:self];
  286.     return self;
  287. }
  288.  
  289.  
  290.  
  291. - windowDidUpdate:sender
  292. {
  293.     return self;
  294. }
  295.  
  296.  
  297. // Shuts up the compiler about unused RCSId
  298. - (const char *) rcsid
  299. {
  300.     return RCSId;
  301. }
  302.  
  303.  
  304. @end
  305.  
  306.  
  307. @implementation AxesPane (Private)
  308.  
  309. - _updateLabelIsThreeD:(BOOL)isThreeD
  310. {
  311.     int i;
  312.  
  313.     for (i = 0 ; i < 3 ; i++)
  314.         [[labelMatrix findCellWithTag:i] setStringValue:[status labelCoord:i]];
  315.  
  316.     [[labelMatrix findCellWithTag:Z_TAG] setEnabled:isThreeD];
  317.     [[labelMatrixLabelMatrix findCellWithTag:Z_TAG]
  318.                  setTextGray:isThreeD? NX_BLACK: NX_DKGRAY];
  319.  
  320.     return self;
  321. }
  322.  
  323.  
  324.  
  325. - _updateTicsIsThreeD:(BOOL)isThreeD
  326. {
  327.     id cell;
  328.     BOOL ticsX = [status ticsCoord:X_TAG];
  329.     BOOL ticsY = [status ticsCoord:Y_TAG];
  330.     BOOL ticsZ = [status ticsCoord:Z_TAG];
  331.  
  332.     [ticsInMatrix selectCellWithTag: [status ticsIn]? 0: 1];
  333.     [ticsInMatrix setEnabled: (ticsX || ticsY || (ticsZ && isThreeD))];
  334.  
  335.     cell = [ticsMatrix findCellWithTag:X_TAG];
  336.     [cell setState:ticsX];
  337.  
  338.     cell = [ticsMatrix findCellWithTag:Y_TAG];
  339.     [cell setState:ticsY];
  340.  
  341.     cell = [ticsMatrix findCellWithTag:Z_TAG];
  342.     if (ticsZ)
  343.         [cell setState:ticsZ && isThreeD];
  344.     [cell setEnabled:isThreeD];
  345.  
  346.     [ticsMatrix display];
  347.  
  348.     return self;
  349. }
  350.  
  351.  
  352.  
  353. - _updateRangeIsThreeD:(BOOL)isThreeD isPolar:(BOOL)isPolar
  354. {
  355.     int state, i;
  356.     id    cell;
  357.                         /* Update X & Y Ranges */
  358.     for (i = 0 ; i < 2 ; i++)  {
  359.     [[rangeAutoMatrix findCellWithTag:i] setState:
  360.                 state = [status autoscaleCoord:i]];
  361.     [cell = [rangeMatrix cellAt:i :0] setDoubleValue: [status minCoord:i]];
  362.     [cell setEnabled:!state];
  363.     [cell = [rangeMatrix cellAt:i :1] setDoubleValue: [status maxCoord:i]];
  364.     [cell setEnabled:!state];
  365.     }
  366.  
  367.  
  368.     /* 
  369.      *  We use the Z controls as R when the plot is polar.  In cases 
  370.      *  like this, the tag of the control will be Z_TAG, so it will 
  371.      *  seem to refer to a Z coordinate instead of an R coordinate.  
  372.      *  We need to be careful, here and elsewhere in Inspector, to 
  373.      *  deal with the control using Z_TAG and deal with Status 
  374.      *  settings using R_TAG if the plot is polar.
  375.      */
  376.     
  377.     i = isPolar? R_TAG :Z_TAG;
  378.     cell = [rangeAutoMatrix findCellWithTag:Z_TAG];
  379.     [cell setTitle:isPolar? "R     " :"Z     "];
  380.     [cell setState:state = [status autoscaleCoord:i]];
  381.     [cell setEnabled:isPolar || isThreeD];
  382.  
  383.     cell = [rangeMatrix cellAt:Z_TAG :0];
  384.     [cell setEnabled:!state && (isPolar || isThreeD)];
  385.     [cell setDoubleValue: [status minCoord:i]];
  386.  
  387.     cell = [rangeMatrix cellAt:Z_TAG :1];
  388.     [cell setEnabled:!state && (isPolar || isThreeD)];
  389.     [cell setDoubleValue: [status maxCoord:i]];
  390.  
  391.     [rangeMatrix display];
  392.     [rangeAutoMatrix display];
  393.  
  394.     return self;
  395. }
  396.  
  397.  
  398.  
  399. @end
  400.